<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { accountApi } from '@/api/controller';
  import { Toastloading, ToastSuccess, ToastWarning } from '@/utils/public';
  import { rechargeChannels } from '@/pinia/getter';
  import Pagination from "@/components/Pagination/index.vue";
  import serachUserid from '@/components/serachUserid/index.vue';
  import { ElMessageBox } from 'element-plus';
  import addUserForm from './addUserForm.vue';
  const addUserFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
    total_price:0,
    forbid_price:0,
    real_price:0,
  })
  const statusOption = [
    {type:0,label:'拉黑中'},
    {type:1,label:'已解封'},
    {type:2,label:'全部'},
  ]
  const handleAdd = ()=>{
    addUserFormRef.value.openDialog()
  }
  const handleDel = (row:any = {})=>{
    const { nickname='', id } = row
    if(!id) return ToastWarning('缺少充值黑名单ID')
    ElMessageBox.confirm(`确定解封用户：${nickname}，的临时充值黑名单吗`, `提示`, {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(async () => {
      const loading = Toastloading();
      accountApi.shortRechargeBlackDel({
        id,
      }).then(()=>{
        ToastSuccess("解封成功!");
        loading.close();
        getList();
      }).catch(()=>{
        loading.close();
      })
    }).catch(() => {});
  }
  const listQuery = reactive({
    page:1,
    limit:20,
    user_id:'',
    uuid:'',
    status:0
  })
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      page:1,
      limit:20,
      user_id:'',
      uuid:''
    })
    getList()
  }
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await accountApi.shortRechargeBlack(listQuery)
    loading.close()
    const { data=[], total=0 } = res.data
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <serachUserid v-model:user_id="listQuery.user_id" />
        </div>
        <div class="labelItem">
          <div class="label">状态：</div>
          <el-select v-model="listQuery.status" placeholder="请选择展示位置">
            <el-option
              v-for="item in statusOption"
              :label="item.label"
              :value="item.type"
            />
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
          <el-button type="primary" @click="handleAdd">新增</el-button>
        </div>
      </div>
    </div>
    <el-table class="xm-main xm-TableCenter" :data="action.list" border>
      <el-table-column width="100" prop="id" label="ID" />
      <el-table-column width="120" prop="user_id" label="用户ID" />
      <el-table-column width="120" prop="uuid" label="用户UUID" />
      <el-table-column min-width="180" show-overflow-tooltip prop="nickname" label="用户昵称" />
      <el-table-column min-width="200" show-overflow-tooltip prop="content" label="说明" />
      <el-table-column min-width="140" prop="pay_type" label="充值渠道">
        <template #default="scoped">
          {{ rechargeChannels.find(res=>res.type == scoped.row.pay_type)?.label || scoped.row.pay_type }}
        </template>
      </el-table-column>
      <el-table-column min-width="140" prop="log_time" label="拉黑时间" />
      <el-table-column min-width="140" prop="updated_at" label="解封时间" />
      <el-table-column min-width="100" prop="is_delete" label="状态">
        <template #default="scoped">
          {{ statusOption.find(res=>res.type == scoped.row.is_delete)?.label || scoped.row.is_delete }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" min-width="80" label="操作">
        <template #default="scoped">
          <el-button type="danger" @click="handleDel(scoped.row)">解封</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <addUserForm ref="addUserFormRef" @update-list="getList" />
  </div>
</template>